/*
 * app_lvgl_disp.c
 *
 *  Created on: 2022年8月23日
 *      Author: hehungAdministrator
 */

#include "app_gui.h"

#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_freertos_hooks.h"
#include "freertos/semphr.h"
#include "lvgl.h"
#include "lvgl_helpers.h"
#include "lv_misc/lv_area.h"
#include "app_rtc.h"
#include <time.h>
#include "es8311.h"
#include "app_rgb.h"

#include "app_common.h"
#include "app_wifi.h"
#include "app_aliyun.h"
#include "app_weather.h"
#if (TTS_ENABLE == STD_ON)
#include "app_tts_voice.h"
#endif /* (TTS_ENABLE == STD_ON) */
#include "app_lamp_mngr.h"

//任务优先级
#define GUI_TASK_PRIO		(9U)
//任务堆栈大小	（单位为字，在32位处理器下，一个字等于4个字节）
#define GUI_TASK_SIZE 		(1024*4U)
//任务句柄
static TaskHandle_t Gui_TaskHandle;

#define TAG                            "app_gui"
#define LV_TICK_PERIOD_MS              (5U)

#define GUI_REFRESH_PERIOS_MS          (15U)
#define GUI_WIFI_LOGO_BLINK_PREIOD_MS  (125U)

// 背景对象
static lv_obj_t *bgk = NULL;
// 显示界面标志
static e_GuiDispType gui_disp_flg = GUI_STARTUP;
// 时间显示标签
static lv_obj_t *time_label = NULL;
static lv_obj_t *time_sec_label = NULL;
static lv_obj_t *date_label = NULL;
// 作品名标签
static lv_obj_t *title_label = NULL;
// wifi连接状态标签
static lv_obj_t *wifi_label = NULL;
// IoT连接状态标签
static lv_obj_t *iot_label = NULL;
// 台灯延时关闭标签
static lv_obj_t *delay_off_label = NULL;
// 学习标签
static lv_obj_t *learn_time_label = NULL;
// 学习时间显示标签
static lv_obj_t *learn_time_dis_label = NULL;
// 学习进度条
static lv_obj_t *learn_time_bar = NULL;
// 台灯亮度标签
static lv_obj_t *lamp_label = NULL;
// 台灯模式标签
static lv_obj_t *lamp_mode_label = NULL;
// lv_led对象
//static lv_obj_t *lamp_led = NULL;
// 日期容器
static lv_obj_t *date_cont = NULL;
// 台灯亮度进度条量规
static lv_obj_t *lamp_bar = NULL;
// 天气容器
static lv_obj_t *wea_cont = NULL;
// 天气标签
static lv_obj_t *wea_label1 = NULL;
static lv_obj_t *wea_label2 = NULL;
static lv_obj_t *wea_label3 = NULL;

// 星期英文字符
static char *week_str[7] =
{
	"日",
	"一",
	"二",
	"三",
	"四",
	"五",
	"六"
};

// 空气质量
static char *aqi_str[6] =
{
	"优",
	"良",
	"轻度污染",
	"中度污染",
	"重度污染",
	"严重污染"
};

extern bool linkkit_GetIotConnStatus(void);

static void lv_tick_task(void *arg);
//static void create_demo_application(void);
static void Gui_TaskCtrl(void *pvParameters);
static void Gui_ShowApplication(void);
static void Gui_InitGUI(void);
static void Gui_ShowMain(void);
static void Gui_ShowWifiLogo(void);
static void Gui_ShowIoTLogo(void);
static void Gui_ShowWeatherInfo(void);


// 创建GUI任务
void Gui_TaskInit(void)
{
	portBASE_TYPE xReturn = pdPASS;

	xReturn = xTaskCreatePinnedToCore(&Gui_TaskCtrl,
									"gui_task",
									GUI_TASK_SIZE,
									NULL,
									GUI_TASK_PRIO,
									Gui_TaskHandle,
									CONFIG_ESP_MAIN_TASK_AFFINITY);
	if(pdPASS != xReturn)
		ESP_LOGE(TAG, "Gui task create failed!");
}


static void Gui_TaskCtrl(void *pvParameters)
{
    (void) pvParameters;

	lv_init();
    /* Initialize SPI or I2C bus used by the drivers */
    lvgl_driver_init();

    lv_color_t* buf1 = heap_caps_malloc(DISP_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
    assert(buf1 != NULL);

    /* Use double buffered when not working with monochrome displays */
    lv_color_t* buf2 = heap_caps_malloc(DISP_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
    assert(buf2 != NULL);

    static lv_disp_buf_t disp_buf;

    uint32_t size_in_px = DISP_BUF_SIZE;

    /* Initialize the working buffer depending on the selected display.
     * NOTE: buf2 == NULL when using monochrome displays. */
    lv_disp_buf_init(&disp_buf, buf1, buf2, size_in_px);

    lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&disp_drv);
    disp_drv.flush_cb = disp_driver_flush;

    disp_drv.buffer = &disp_buf;
    lv_disp_drv_register(&disp_drv);

    /* Create and start a periodic timer interrupt to call lv_tick_inc */
    const esp_timer_create_args_t periodic_timer_args = {
        .callback = &lv_tick_task,
        .name = "periodic_gui"
    };
    esp_timer_handle_t periodic_timer;
    ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer));
    ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, LV_TICK_PERIOD_MS * 1000));

    /* Init the GUI */
    Gui_InitGUI();

    while (1)
    {
    	/* 显示动态数据 */
    	Gui_ShowApplication();

    	/* Delay 1 tick (assumes FreeRTOS tick is 15ms */
        vTaskDelay(pdMS_TO_TICKS(GUI_REFRESH_PERIOS_MS));

        lv_task_handler();
    }

    /* A task should NEVER return */
    free(buf1);
#ifndef CONFIG_LV_TFT_DISPLAY_MONOCHROME
    free(buf2);
#endif
    vTaskDelete(NULL);
}

// lvgl心跳定时器函数
static void lv_tick_task(void *arg) {
    (void) arg;

    lv_tick_inc(LV_TICK_PERIOD_MS);
}


// 显示界面初始化
static void Gui_InitGUI(void)
{
	gui_disp_flg = GUI_MAIN;

    bgk = lv_obj_create(lv_scr_act(), NULL);
    //清空对象风格
    lv_obj_clean_style_list(bgk, LV_OBJ_PART_MAIN);
    //设置颜色覆盖度100%，数值越低，颜色越透
    lv_obj_set_style_local_bg_opa(bgk, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_100);
    //设置背景颜色为绿色
    lv_obj_set_style_local_bg_color(bgk, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(255, 255, 255));
    //省去下方两行代码，默认是从0,0处开始绘制
    //设置X轴起点
    lv_obj_set_x(bgk, 0);
    //设置Y轴起点
    lv_obj_set_y(bgk, 0);
    lv_obj_set_size(bgk, 320, 240);//设置覆盖大小

	// 时间日期容器初始化
	date_cont = lv_cont_create(lv_scr_act(), NULL);
    lv_obj_set_auto_realign(date_cont, true);                    /*Auto realign when the size changes*/
	lv_obj_align_origo(date_cont, NULL, LV_ALIGN_CENTER, 0, -50);  /*This parametrs will be sued when realigned*/
	lv_cont_set_fit(date_cont, LV_FIT_TIGHT);
	lv_cont_set_layout(date_cont, LV_LAYOUT_OFF);
	lv_obj_set_width(date_cont, 180);
//	lv_obj_set_height(date_cont, 60);

	// 时间显示初始化
	time_label = lv_label_create(date_cont, NULL);
    lv_obj_set_style_local_text_font(time_label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_36);
	lv_label_set_long_mode(time_label, LV_LABEL_LONG_BREAK);
	lv_label_set_recolor(time_label, true);
	lv_label_set_align(time_label, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(time_label, 120);
	lv_obj_align(time_label, NULL, LV_ALIGN_CENTER, 0, 0);

	// 初始化秒显示
	time_sec_label = lv_label_create(date_cont, NULL);
	lv_obj_set_style_local_text_font(time_sec_label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_16);
	lv_label_set_long_mode(time_sec_label, LV_LABEL_LONG_BREAK);
	lv_label_set_recolor(time_sec_label, true);
	lv_label_set_align(time_label, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(time_sec_label, 30);
	lv_obj_align(time_sec_label, NULL, LV_ALIGN_CENTER, 73, 23);

	// 初始化日期
	date_label = lv_label_create(date_cont, NULL);
	lv_obj_set_style_local_text_font(date_label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &myFont);
	lv_label_set_long_mode(date_label, LV_LABEL_LONG_BREAK);
	lv_label_set_recolor(date_label, true);
	lv_label_set_align(date_label, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(date_label, 160);
	lv_obj_align(date_label, NULL, LV_ALIGN_CENTER, 0, 30);

	// 初始化作品标题
	title_label = lv_label_create(lv_scr_act(), NULL);
	lv_obj_set_style_local_text_font(title_label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &myFont);
	lv_label_set_long_mode(title_label, LV_LABEL_LONG_BREAK);
	lv_label_set_recolor(title_label, true);
	lv_label_set_align(title_label, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(title_label, 160);
	lv_obj_align(title_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 5);
	lv_label_set_text(title_label, "#000000 智能网络台灯");

	// wifi显示初始化
	wifi_label = lv_label_create(lv_scr_act(), NULL);
	lv_obj_set_style_local_text_font(wifi_label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_16);
	lv_label_set_long_mode(wifi_label, LV_LABEL_LONG_BREAK);
	lv_label_set_recolor(wifi_label, true);
	lv_label_set_align(wifi_label, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(wifi_label, 16);
	lv_obj_align(wifi_label, NULL, LV_ALIGN_IN_TOP_LEFT, 46, 5);
	lv_label_set_text(wifi_label, LV_SYMBOL_WIFI);

	// iot显示初始化
	iot_label = lv_label_create(lv_scr_act(), NULL);
	lv_obj_set_style_local_text_font(iot_label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_16);
	lv_label_set_long_mode(iot_label, LV_LABEL_LONG_BREAK);
	lv_label_set_recolor(iot_label, true);
	lv_label_set_align(iot_label, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(iot_label, 32);
	lv_obj_align(iot_label, NULL, LV_ALIGN_IN_TOP_LEFT, 70, 5);
	lv_label_set_text(iot_label, "IoT");

	// delay_off显示初始化
	delay_off_label = lv_label_create(lv_scr_act(), NULL);
	lv_obj_set_style_local_text_font(delay_off_label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_16);
	lv_label_set_long_mode(delay_off_label, LV_LABEL_LONG_BREAK);
	lv_label_set_recolor(delay_off_label, true);
	lv_label_set_align(delay_off_label, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(delay_off_label, 32);
	lv_obj_align(delay_off_label, NULL, LV_ALIGN_IN_TOP_RIGHT, -46, 5);
	lv_label_set_text(delay_off_label, "DO");  /* DO - Delayed Off */

	// 台灯标签初始化
	lamp_label = lv_label_create(lv_scr_act(), NULL);
	lv_obj_set_style_local_text_font(lamp_label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_16);
	lv_label_set_long_mode(lamp_label, LV_LABEL_LONG_BREAK);
	lv_label_set_recolor(lamp_label, true);
	lv_label_set_align(lamp_label, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(lamp_label, 16);
	lv_obj_align(lamp_label, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, -8, 10);
	lv_label_set_text(lamp_label, LV_SYMBOL_EYE_OPEN);

	// 台灯设置模式标签
	lamp_mode_label = lv_label_create(lv_scr_act(), NULL);
	lv_obj_set_style_local_text_font(lamp_mode_label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &myFont);
	lv_label_set_long_mode(lamp_mode_label, LV_LABEL_LONG_BREAK);
	lv_label_set_recolor(lamp_mode_label, true);
	lv_label_set_align(lamp_mode_label, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(lamp_mode_label, 32);
	lv_obj_align(lamp_mode_label, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, -2, -5);
	lv_label_set_text(lamp_mode_label, "#0000ff 自动");

	// 台灯亮度进度条初始化
	lamp_bar = lv_bar_create(lv_scr_act(), NULL);
	lv_obj_set_size(lamp_bar, 20, 180);
	lv_bar_set_range(lamp_bar, 0, 100);
	lv_obj_align(lamp_bar, NULL, LV_ALIGN_IN_RIGHT_MID, -5, -15);
	lv_bar_set_anim_time(lamp_bar, 60);
	// LV_ANIM_ON: 是否使能动画效果
	lv_bar_set_value(lamp_bar, Lamp_GetDutyCycleRatio(), LV_ANIM_OFF);
    //设置颜色覆盖度100%，数值越低，颜色越透
//    lv_obj_set_style_local_bg_opa(lamp_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_OPA_60);
//    //设置背景以及前景颜色
//    lv_obj_set_style_local_bg_color(lamp_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_COLOR_RED);
//    lv_obj_set_style_local_bg_color(lamp_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GRAY);

	// 学习时间标签
	learn_time_label = lv_label_create(lv_scr_act(), NULL);
	lv_obj_set_style_local_text_font(learn_time_label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &myFont);
	lv_label_set_long_mode(learn_time_label, LV_LABEL_LONG_BREAK);
	lv_label_set_recolor(learn_time_label, true);
	lv_label_set_align(learn_time_label, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(learn_time_label, 16);
	lv_obj_align(learn_time_label, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 6, -10);
	lv_label_set_text(learn_time_label, ""); // 显示一个时钟awesome图标

	// 学习时间显示标签
	learn_time_dis_label = lv_label_create(lv_scr_act(), NULL);
	lv_obj_set_style_local_text_font(learn_time_dis_label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_16);
	lv_label_set_long_mode(learn_time_dis_label, LV_LABEL_LONG_BREAK);
	lv_label_set_recolor(learn_time_dis_label, true);
	lv_label_set_align(learn_time_dis_label, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(learn_time_dis_label, 70);
	lv_obj_align(learn_time_dis_label, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -6);
	lv_label_set_text(learn_time_dis_label, "00:00");

	//学习时间进度条
	learn_time_bar = lv_bar_create(lv_scr_act(), NULL);
	lv_obj_set_size(learn_time_bar, 20, 180);
	lv_bar_set_range(learn_time_bar, 0, LAMP_MAX_LEARN_TIME);
	lv_obj_align(learn_time_bar, NULL, LV_ALIGN_IN_LEFT_MID, 5, -20);
	lv_bar_set_anim_time(learn_time_bar, 500);
	// LV_ANIM_ON: 显示动画效果
	lv_bar_set_value(learn_time_bar, 0, LV_ANIM_OFF);

	// 天气显示容器
	wea_cont = lv_cont_create(lv_scr_act(), NULL);
    lv_obj_set_auto_realign(wea_cont, true);                    /*Auto realign when the size changes*/
	lv_obj_align_origo(wea_cont, NULL, LV_ALIGN_CENTER, 0, 40);  /*This parametrs will be sued when realigned*/
	lv_cont_set_fit(wea_cont, LV_FIT_TIGHT);
	lv_cont_set_layout(wea_cont, LV_LAYOUT_OFF);
	lv_obj_set_width(wea_cont, 180);
//	lv_obj_set_height(wea_cont, 80);

	// 天气标签1，主要显示当前天气和温湿度信息
	wea_label1 = lv_label_create(wea_cont, NULL);
	lv_obj_set_style_local_text_font(wea_label1, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &myFont);
	lv_label_set_long_mode(wea_label1, LV_LABEL_LONG_BREAK);
	lv_label_set_recolor(wea_label1, true);
	lv_label_set_align(wea_label1, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(wea_label1, 180);
	lv_obj_align(wea_label1, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
	lv_label_set_text(wea_label1, "");

	// 天气标签2，主要显示空气质量与压强与温度范围
	wea_label2 = lv_label_create(wea_cont, NULL);
	lv_obj_set_style_local_text_font(wea_label2, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &myFont);
	lv_label_set_long_mode(wea_label2, LV_LABEL_LONG_SROLL_CIRC);
	lv_label_set_recolor(wea_label2, true);
	lv_label_set_align(wea_label2, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(wea_label2, 180);
	lv_obj_align(wea_label2, NULL, LV_ALIGN_CENTER, 0, 25);
	lv_label_set_text(wea_label2, "");

	// 天气标签3，主要显示最近六天的天气
	wea_label3 = lv_label_create(wea_cont, NULL);
	lv_obj_set_style_local_text_font(wea_label3, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, &myFont);
	lv_label_set_long_mode(wea_label3, LV_LABEL_LONG_SROLL_CIRC);
	lv_label_set_recolor(wea_label3, true);
	lv_label_set_align(wea_label3, LV_LABEL_ALIGN_CENTER);
	lv_obj_set_width(wea_label3, 180);
	lv_obj_align(wea_label3, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 5);
	lv_label_set_text(wea_label3, "");

}

// 主显示界面GUI
static void Gui_ShowMain(void)
{
	struct tm current_time;
	time_t now;
	s_LearnTimeType learn_time;

	// 获取最新时间
	time(&now);
	localtime_r(&now, &current_time);

	// 显示时间
	lv_label_set_text_fmt(time_label, "#0000ff %02d:%02d",
			                          current_time.tm_hour,
									  current_time.tm_min);
	lv_label_set_text_fmt(time_sec_label, "#0000ff %02d", current_time.tm_sec);
	// 显示日期
	lv_label_set_text_fmt(date_label, "#000000 %02d月%02d日  星期%s",
									  current_time.tm_mon + 1,
									  current_time.tm_mday,
									  week_str[current_time.tm_wday]);

	// 显示天气信息
	Gui_ShowWeatherInfo();
	// wifi连接状态logo显示
	Gui_ShowWifiLogo();
	// 显示连接aliyun平台的IOT logo
	Gui_ShowIoTLogo();
	// 显示延时关闭logo
	if (1U == Lamp_GetDelayOffStatus())
		lv_label_set_text(delay_off_label, "DO");
	else
		lv_label_set_text(delay_off_label, "");

	// 显示台灯亮度
	lv_bar_set_value(lamp_bar, Lamp_GetDutyCycleRatio(), LV_ANIM_OFF);

	// 显示学习时间
	learn_time = Lamp_GetLearnTime();
	lv_bar_set_value(learn_time_bar, learn_time.learn_time_min, LV_ANIM_OFF);

	// 电源已经关闭，但是因为延时关闭的原因还没有真实关闭电源
	if (Lamp_GetDelayOffPowerStatus() == 1U)
	{
		// 使用学习标签显示延时关闭的时间
		if (Lamp_GetDelayOffRemainTime() != LAMP_DELAY_OFF_TIME)
			lv_label_set_text_fmt(learn_time_dis_label, "%02d", LAMP_DELAY_OFF_TIME - Lamp_GetDelayOffRemainTime());
		else
			lv_label_set_text(learn_time_dis_label, "");
	}
	else
	{
		if (((learn_time.learn_time_min == 0) && (learn_time.learn_time_sec == 0)))
		{
			// 显示学习剩余时间标签
			lv_label_set_text(learn_time_dis_label, "");
		}
		else
		{
			// 显示学习剩余时间标签
			lv_label_set_text_fmt(learn_time_dis_label, "#ff0000 %02d:%02d",
					              learn_time.learn_time_min,
								  learn_time.learn_time_sec);
		}
	}

	// 显示台灯的控制模式
	switch (Lamp_GetCtrlMode())
	{
		case LAMP_AUTO: lv_label_set_text(lamp_mode_label, "#0000ff 自动"); break;
		case LAMP_MANUAL: lv_label_set_text(lamp_mode_label, "#0000ff 手动"); break;
		case LAMP_READING: lv_label_set_text(lamp_mode_label, "#0000ff 阅读"); break;
		case LAMP_SLEEPING: lv_label_set_text(lamp_mode_label, "#0000ff 睡觉"); break;
	}
}

// 显示天气信息
static void Gui_ShowWeatherInfo(void)
{
	s_WeatherInfoType wea_c;
	s_WeatherInfoSimpleType *wea_seven;
	int aqi_num = 0;
	uint8_t air_aqi_level = 0;

	wea_c = Weather_GetCurrentWea();
	wea_seven = Weather_GetSevenWea();
	if (1 == wea_c.succ_flg)
	{
		// 获取空气质量并转换为数字
		sscanf(wea_c.air, "%d", &aqi_num);
		if ((aqi_num >= 0) && (aqi_num <= 50))
		{
			air_aqi_level = 0;
		}
		else if ((aqi_num >= 51) && (aqi_num <= 100))
		{
			air_aqi_level = 1;
		}
		else if ((aqi_num >= 101) && (aqi_num <= 150))
		{
			air_aqi_level = 2;
		}
		else if ((aqi_num >= 151) && (aqi_num <= 200))
		{
			air_aqi_level = 3;
		}
		else if ((aqi_num >= 201) && (aqi_num <= 300))
		{
			air_aqi_level = 4;
		}
		else
		{
			air_aqi_level = 5;
		}

		lv_label_set_text_fmt(wea_label1, "#ff0000 %s  %s℃ | %s", wea_c.weather, wea_c.temp, wea_c.humi);
		lv_label_set_text_fmt(wea_label2, "AQI:%s(%s) | %s℃~%s℃", wea_c.air, aqi_str[air_aqi_level], wea_c.temp_l, wea_c.temp_h);
	}
	else
	{
		lv_label_set_text(wea_label2, "天气未知");
	}

	if (1 == wea_seven[0].succ_flg)
	{
		lv_label_set_text_fmt(wea_label3, "%s:%s %s℃~%s℃ | "
					                          "%s:%s %s℃~%s℃ | "
					                          "%s:%s %s℃~%s℃ | "
					                          "%s:%s %s℃~%s℃ | "
					                          "%s:%s %s℃~%s℃ | "
					                          "%s:%s %s℃~%s℃",
											  wea_seven[1].date, wea_seven[1].weather, wea_seven[1].temp_l, wea_seven[1].temp_h,
											  wea_seven[2].date, wea_seven[2].weather, wea_seven[2].temp_l, wea_seven[2].temp_h,
											  wea_seven[3].date, wea_seven[3].weather, wea_seven[3].temp_l, wea_seven[3].temp_h,
											  wea_seven[4].date, wea_seven[4].weather, wea_seven[4].temp_l, wea_seven[4].temp_h,
											  wea_seven[5].date, wea_seven[5].weather, wea_seven[5].temp_l, wea_seven[5].temp_h,
											  wea_seven[6].date, wea_seven[6].weather, wea_seven[6].temp_l, wea_seven[6].temp_h);
	}
}

// wifi logo显示逻辑
static void Gui_ShowWifiLogo(void)
{
	static uint16_t cnt = 0;
	static int8_t flg = 0;

	if (0U == Wifi_GetConnectStatus())
	{
		if (cnt > (uint16_t)(GUI_WIFI_LOGO_BLINK_PREIOD_MS/GUI_REFRESH_PERIOS_MS))
		{
			cnt = 0;
			flg ^= 1;
		}
		else
		{
			cnt ++;
		}

		if (1 == flg)
		{
			if (Lamp_GetPowerState() == 1U)
				Rgb_RedOn();
			lv_label_set_text(wifi_label, LV_SYMBOL_WIFI);
		}
		else
		{
			if (Lamp_GetPowerState() == 1U)
				Rgb_Off();
			lv_label_set_text(wifi_label, "");
		}
	}
	else
	{
		lv_label_set_text(wifi_label, LV_SYMBOL_WIFI);
	}
}

// 显示IOT logo
static void Gui_ShowIoTLogo(void)
{
	static uint16_t cnt = 0;
	static int8_t flg = 0;

	if (cnt > (uint16_t)(GUI_WIFI_LOGO_BLINK_PREIOD_MS/GUI_REFRESH_PERIOS_MS))
	{
		cnt = 0;
		flg ^= 1;
	}
	else
	{
		cnt ++;
	}

	if (false == linkkit_GetIotConnStatus())
	{
		if (1 == flg)
		{
			if (Lamp_GetPowerState() == 1U)
				if (1U == Wifi_GetConnectStatus())
					Rgb_BlueOn();
			lv_label_set_text(iot_label, "IoT");
		}
		else
		{
			if (Lamp_GetPowerState() == 1U)
				if (1U == Wifi_GetConnectStatus())
					Rgb_Off();
			lv_label_set_text(iot_label, "");
		}
	}
	else
	{
		if (Lamp_GetPowerState() == 1U)
		{
			if (1 == flg)
			{
				Rgb_GreenOn();
			}
			else
			{
				Rgb_Off();
			}
		}

		lv_label_set_text(iot_label, "IoT");
	}
}

// 显示处理程序
static void Gui_ShowApplication(void)
{
	switch (gui_disp_flg)
	{
		case GUI_STARTUP:
		{
			break;
		}
		case GUI_MAIN:
		{
			Gui_ShowMain();
			break;
		}
		default:
			break;
	}
}

